package com.erhirent.view;

import java.util.InputMismatchException;

import com.erhairent.tools.InputTools;

public class ManergerView extends View {

	AddView add = new AddView();
	ModView mod = new ModView();
	ManergerqueryAll query = new ManergerqueryAll();
	ManerqueryRecord record = new ManerqueryRecord();

	@Override
	public View showView() {
		System.out.println("输入0:   退出");
		System.out.println("输入1+汽车编号:   查看指定汽车");
		System.out.println("输入2:   查看所有汽车");
		System.out.println("输入3:   添加汽车");
		System.out.println("输入4:   修改汽车信息");
		System.out.println("输入5:   查看租车记录");
		System.out.println("请选择:");
		return mView;
	}

	public void chooseNumber1() {
		String chooseNum;
		int i = 0;
		int j = 0;
		while (true) {
			try {
				chooseNum = InputTools.next();
				if (chooseNum.length() == 2) {
					System.out.println("没有该选项,重新输入");
					continue;
				} else if (chooseNum.length() > 2) {
					j = Integer.valueOf(chooseNum.substring(2));
				}
				break;
			} catch (InputMismatchException e) {
				System.out.println("只可以输入数字,不可以输入其它字符,请重新输入");
				InputTools.next();
			}
		}
		i = Integer.valueOf(chooseNum.substring(0, 1));
		switch (i) {
		case 1:
			// 管理员指定查询
			mcar.manergerquery(j);

			showView();
			chooseNumber1();
			break;
		case 2:
			// 查询所有
			query.showView();

			showView();
			chooseNumber1();
			break;
		case 3:
			// 添加汽车
			add.showView();

			showView();
			chooseNumber1();
			break;
		case 4:
			// 修改汽车
			mod.showView();

			showView();
			chooseNumber1();
			break;
		case 5:
			// 查看租车记录
			record.showView();

			showView();
			chooseNumber1();
			break;
		case 0:
			System.out.println("欢迎下次租车!");
			break;

		default:
			break;
		}
	}

}
